from abc import ABC, abstractmethod

from src.json_patch import JSONPatch, StatusPatch
from .mimo import MimoProcessor, MimoStatus

PlotPoints = tuple[list[int], list[float]]


class MimoPlotProcessor(MimoProcessor):
    """
    预期消息体格式:
    ```jsonc
    {
        "id": 1,    // 报告 ID
        "args": {
            "receiveAntennas": 2,   // int   > 1        接收天线数
            "modulationMode": 1,    // int   [1 ~ 3]    调制方式
            "noiseRate": 1,         // float [-10 ~ 20] 信噪比
            "counts": 10000,        // int   [1_000, 100_000]
        },
    }
    ```
    预取响应`body.data`
    ```jsonc
    [{
            "op": "add",
            "path": "/plot/result",
            "value": [
                [1, 2, 3, 4, 5],            // list[int]
                [1.1, 2.2, 3.3, 4.4, 5.5],  // list[float]
            ],
    }]
    ```
    """

    def __init__(self, body: bytes) -> None:
        super().__init__(body)
        self.counts = float(self.args["counts"])

    def build_data(self, points: PlotPoints):
        return JSONPatch().add_patch(
            "add",
            "/plot/result",
            points,
        )

    def get_success_status_patch(self) -> StatusPatch:
        return StatusPatch().add_patch("remove", MimoStatus.PLOTTING.value)


class MimoPlotAdaptor(ABC):
    @abstractmethod
    def mimo_plot(self, processor: MimoPlotProcessor) -> PlotPoints: ...
